package sg.edu.nus.iss.billing.dao;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Calendar;

import sg.edu.nus.iss.billing.model.BaseModel;
import sg.edu.nus.iss.billing.model.charge.Rate;
import sg.edu.nus.iss.billing.utils.PropertiesRead;

/**
 * @author Thurein, Yin Ni Tun, Zhou Zifeng
 *
 */
public class RateDAO extends BaseModel {

	private static final long serialVersionUID = 1L;

	private static RateDAO rateProps;

	private PropertiesRead propertiesRead;

	private Calendar calender;

	private RateDAO() {
		calender = Calendar.getInstance();
		calender.set(2011, 1, 1);

		propertiesRead = new PropertiesRead();
		FileInputStream fis;
		try {
			fis = new FileInputStream("properties/serviceRate.properties");
			propertiesRead.load(fis);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static synchronized RateDAO getInstance() {
		if (rateProps == null) {
			rateProps = new RateDAO();
		}
		return rateProps;
	}

	public Rate getDigitalMthlySubscription() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("digitalMthlySubscription")), calender.getTime());
		rate.setRateType("digitalMthlySubscription");
		return rate;

	}

	public Rate getDigitalMthlyCallTransferSubscription() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("digitalMthlyCallTransferSubscription")),
				calender.getTime());
		rate.setRateType("digitalMthlyCallTransferSubscription");
		return rate;

	}

	public Rate getDigitalLocalCallPerSec() {
		Rate rate =new Rate(Double.parseDouble(propertiesRead.getProperty("digitalLocalCallPerSec")), calender.getTime());
		rate.setRateType("digitalLocalCallPerSec");
		return rate;

	}

	public Rate getDigitalIDDCallPerSec() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("digitalIDDCallPerSec")), calender.getTime());
		rate.setRateType("digitalIDDCallPerSec");
		return rate;
	}

	public Rate getMobileMthlySubscription() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("mobileMthlySubscription")), calender.getTime());
		rate.setRateType("mobileMthlySubscription");
		return rate;
	}

	public Rate getMobileMthlyDataServiceSubscription() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("mobileMthlyDataServiceSubscription")),
				calender.getTime());
		rate.setRateType("mobileMthlyDataServiceSubscription");
		return rate;
	}

	public Rate getMobileLocalCallPerSec() {
		Rate rate =new  Rate(Double.parseDouble(propertiesRead.getProperty("mobileLocalCallPerSec")), calender.getTime());
		rate.setRateType("mobileLocalCallPerSec");
		return rate;
	}

	public Rate getMobileIDDCallPerSec() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("mobileIDDCallPerSec")), calender.getTime());
		rate.setRateType("mobileIDDCallPerSec");
		return rate;
	}

	public Rate getMobileRoamingCallPerSec() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("mobileRoamingCallPerSec")), calender.getTime());
		rate.setRateType("mobileRoamingCallPerSec");
		return rate;
	}

	public Rate getCableTVMthlySubscription() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("cableTVMthlySubscription")), calender.getTime());
		rate.setRateType("cableTVMthlySubscription");
		return rate;
	}

	public Rate getCableTVAdditionalChannelSubscription() {
		Rate rate = new Rate(Double.parseDouble(propertiesRead.getProperty("cableTVAdditionalChannelSubscription")),
				calender.getTime());
		rate.setRateType("cableTVAdditionalChannelSubscription");
		return rate;
	}
	
	public double getAdditionalChSubscriptionChargeRate() {
		return Double.parseDouble(propertiesRead.getProperty("AdditionalChSubscriptionChargeRate"));
	}
	
}
